/* $Header: clock_ui.h,v 2.2 01/10/02 10:30:13 przybyls Exp $ */

/***********************************************************************/
/* INCLUDE FILE NAME:  clock_ui.h                                      */
/* ==================                                                  */
/*                                                                     */
/* Author:  Tom Przybylski                                             */
/*                                                                     */
/* COMMENT:                                                            */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

#ifndef CLOCKUI_H
#define CLOCKUI_H

/*****************************/
/*   IFDEFS                  */
/*****************************/


/*****************************/
/*   SYMBOLIC CONSTANTS      */
/*****************************/


#define FROZEN_YEAR   00  /* Uninitialized real-time clock default setting */
#define FROZEN_MONTH  4
#define FROZEN_DAY    1
#define FROZEN_HOUR   0
#define FROZEN_MINUTE 0
#define FROZEN_SECOND 0

/*****************************/
/*   MACROS                  */
/*****************************/


/*****************************/
/*   TYPEDEFS                */
/*****************************/

extern RESOURCE Clock_Table_Exclusive_Lock;

extern DATETIME DateTime;
extern INT32    Last_Time;

#pragma SECTION DATA=pfail

extern TIME_TABLE Clock_Table;
extern BIT8       Clock_Hosed;
extern BIT8       Calendar_Hosed;

#pragma SECTION UNDO

extern const DATETIME Frozen_Date_Time;


typedef enum {
         CT_NULL_EVENT          = 0,  /* Placeholder, indicates no event */
         CT_VALVE_1             = 1,  /* NOTE:  Valve 1-8 positions map  */
         CT_VALVE_2             = 2,  /*  to events 1-8, used by check-  */
         CT_VALVE_3             = 3,  /*  ing functions.                 */
         CT_VALVE_4             = 4,
         CT_VALVE_5             = 5,
         CT_VALVE_6             = 6,
         CT_VALVE_7             = 7,
         CT_VALVE_8             = 8,
         CT_MULTI_VALVE         = 9,
         CT_BLANK_RUN           = 10,
         CT_START_SEQ           = 11,
         CT_PREP_RUN            = 12,
         CT_COL_COMP1           = 13,
         CT_COL_COMP2           = 14,
         CT_COL_COMP_BOTH       = 15,
         CT_LOAD_METHOD         = 16,
         CT_LOAD_SEQ            = 17,
         CT_DET_OFFSET          = 18,
         CT_Available_Entry     = 19   /* last entry */

       } CTT_EVENT;


/*****************************/
/*   FUNCTION PROTOTYPES     */
/*****************************/


void  UpdateTimeOfDay (void);
INT32 GetClockTime (void);
INT32 GetFullClockTime (void);
INT32 GetFullDate (void);
INT32 GetDate ( DATETIME *datetime );
INT32 GetTime ( DATETIME *datetime );

UI_ERR AddClockTableEntry ( INT32 time, U_INT8 type, INT32 parm, U_INT8 *new_entry_num );
UI_ERR DeleteClockTableEntry ( U_INT8 entry_num );
void   DeleteEntireClockTable( void );
UI_ERR GetClockTableEntry ( U_INT8 entry_num, INT32 *time, U_INT8 *type, INT32 *parm );
UI_ERR ChangeClockTableEntryParm ( U_INT8 entry_num, INT32 parm );
UI_ERR ChangeClockTableEntryTime ( U_INT8 entry_num, INT32 time, U_INT8 *new_entry_num );
INT32  MaxClockTableEntry (void);

UI_ERR CheckClockTime (INT32 time);          /* hhmm   */
UI_ERR CheckFullClockTime (INT32 fulltime);  /* hhmmss */
UI_ERR SetClockTime (INT32 time);            /* hhmm   */
UI_ERR SetFullClockTime (INT32 fulltime);    /* hhmmss */
UI_ERR CheckDate (INT32 date);
UI_ERR SetDate (INT32 date);

UI_ERR CheckClockTableType (CTT_EVENT type);
UI_ERR CheckClockTableParam (CTT_EVENT type, INT32 param);

void SetUpDefaultClockTable ( void );
void ExecuteClockTable ( void );
void InitializeRealTimeClock (void);
void ResetClockTablePointer ( void );

void CTMultiValve (INT32 parm);
void CTBlankRun (INT32 parm);
void CTStartSeq (INT32 parm);
void CTPrepRun (INT32 parm);
void CTColComp1 (INT32 parm);
void CTColComp2 (INT32 parm);
void CTColCompBoth (INT32 parm);
void CTLoadMethod (INT32 method);
void CTLoadSequence (INT32 sequence);
void CTDetOffsetSeek (INT32 sequence);
void CTAnnotate (U_INT32 msg, INT32 parm);
void CTErrorAnnotate (U_INT32 msg, INT32 parm);
void CTValveAnnotate (U_INT8 valve, INT32 parm);

void SetDateTime( DATETIME *datetime );

UI_ERR SetDayMonthYear(DATETIME *datetime, INT32 date );
UI_ERR SetHourMinuteSecond(DATETIME *datetime, INT32 time );
void   InitializeDateTime( DATETIME *pdatetime );

BIT8   DateIsUninitialized (DATETIME when);

U_INT32 SecondsSince1980 (DATETIME datetime);
DATETIME TimeFromSeconds ( U_INT32 seconds );

#endif
